package com.zhentao.controller;


import com.zhentao.common.enums.admin.AdWithdrawal;
import com.zhentao.common.enums.dto.AdAdWithdrawalDto;
import com.zhentao.dtos.Result;
import com.zhentao.helper.ThreadLocalUtil;
import com.zhentao.service.AdWithdrawalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


@RestController
@RequestMapping("/admin")
public class AdWithdrawalController {

    @Autowired
    private AdWithdrawalService adWithdrawalService;
    //投诉列表
    @RequestMapping(value = "/withdrawa/withdrawaList")
    private Result list(@RequestBody AdAdWithdrawalDto adWithdrawalDto){
        return adWithdrawalService.AdWithdrawalList(adWithdrawalDto);
    }
    //核审通过
    @RequestMapping(value = "/withdrawa/withdrawaApprove")
    private Result withdrawaApprove(@RequestParam("withdrawalId") Integer withdrawalId){
        AdWithdrawal byId = adWithdrawalService.getById(withdrawalId);
        byId.setStatus(1);
        byId.setApprovalDate(new Date());
//        byId.setApprovalBy(Integer.valueOf(ThreadLocalUtil.get()));
        boolean b = adWithdrawalService.updateById(byId);
        if (b){
            return Result.success();
        }else {
            return Result.error();
        }
    }

    //审批拒绝
    @RequestMapping(value = "/withdrawa/withdrawaReject")
    private Result updStatus(@RequestBody AdWithdrawal withdrawal){
        withdrawal.setStatus(2);
        withdrawal.setApprovalDate(new Date());
//        withdrawal.setApprovalBy(Integer.valueOf(ThreadLocalUtil.get()));
        boolean b = adWithdrawalService.updateById(withdrawal);
        if (b){
            return Result.success();
        }else {
            return Result.error();
        }
    }
}
